package com.zhss.redis.bitmap;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2021/11/8
 */
public class UserOperationLogDemo {
	HostAndPort hostAndPort = new HostAndPort("121.4.79.149", 6379);
	Jedis jedis = new Jedis(hostAndPort);

	public static void main(String[] args) {
		UserOperationLogDemo userOperationLogDemo = new UserOperationLogDemo();
		userOperationLogDemo.save("操作1", 1L);
		userOperationLogDemo.save("操作2", 1L);
		userOperationLogDemo.save("操作3", 1L);
		System.out.println(userOperationLogDemo.hasOperation("操作1", 1L));
		System.out.println(userOperationLogDemo.hasOperation("操作1", 11L));
		System.out.println(userOperationLogDemo.hasOperation("操作2", 11L));
		System.out.println(userOperationLogDemo.hasOperation("操作2", 1L));

	}

	public void save(String operation, Long userId) {
		String today = LocalDate.now().format(DateTimeFormatter.ISO_DATE);
		jedis.setbit("operation::" + operation + "::" + today + "::log", userId, String.valueOf(userId));
	}

	public boolean hasOperation(String operation, Long userId) {
		String today = LocalDate.now().format(DateTimeFormatter.ISO_DATE);
		return jedis.getbit("operation::" + operation + "::" + today + "::log", userId);
	}
}
